import java.util.LinkedList;
import java.util.Queue;

//用两个队列实现栈
class MyStack {
    //两个队列
    Queue<Integer> queue1;
    Queue<Integer> queue2;

    //初始化队列
    public MyStack() {
        queue1 = new LinkedList<Integer>();
        queue2 = new LinkedList<Integer>();
    }

    //入栈
    public void push(int x) {
        queue2.offer(x);
        while(!queue1.isEmpty()) {
            queue2.offer(queue1.poll());
        }
        //queue1 与 queue2 交换
        Queue<Integer> temp = queue1;
        queue1 = queue2;
        queue2 = temp;
    }

    //出栈
    public int pop() {
        return queue1.poll();
    }

    //获取栈顶元素
    public int top() {
        return queue1.peek();
    }

    //判空
    public boolean empty() {
        return queue1.isEmpty();
    }
}

